﻿@using Abp.Application.Services.Dto;
@using FwProject.Settlement
@using FwProject.Settlement.Dto
@using FwProject.Core.SettlementInfoModel
@using X.PagedList
@model IPagedList<SettlementReceivableDto>
@{
    ViewBag.Title = "收据查询";
}
@section styles{
    <link href="~/Theme/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Theme/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <style type="text/css">
        .input-group[class*=col-] {
            padding: 0 15px;
        }
    </style>
}
<div class="row wrapper wrapper-content animated fadeInRight">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>@ViewBag.Title</h5>
                <div class="ibox-tools">
                    <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                    </a>
                    <a class="dropdown-toggle" data-toggle="dropdown" href="buttons.html#">
                        <i class="fa fa-wrench"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-user">
                        <li>
                            <a href="javascript:Print()">打印</a>
                        </li>
                        <li>
                            <a href="javascript:Export()">导出</a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="ibox-content">
                <div class="m-b-sm m-t-sm">
                    <form class="form-horizontal" id="form" asp-controller="Settlement" asp-action="Index" data-ajax="true" data-ajax-update="#data_list" data-ajax-method="Get" data-ajax-mode="replace" data-ajax-success="LoadDataSuccessMessage">
                        <input type="hidden" id="size" name="size" value="0" />
                        <div class="row">
                            <div class="col-md-3 col-lg-2">
                                <label class="control-label col-md-4 col-lg-4">餐厅：</label>
                                <div class="input-group">
                                    <input type="text" name="RestaurantName" id="RestaurantName" placeholder="请输入餐厅名称" class="input-sm form-control">
                                </div>
                            </div>
                            <div class="col-md-3 col-lg-2">
                                <label class="control-label col-md-5 col-lg-4">收款人：</label>
                                <div class="input-group">
                                    @Html.DropDownList("DriverName", ViewBag.Cashier as IEnumerable<SelectListItem>, "全部", new { @class = "form-control numbrs", id = "DriverName" })
                                </div>
                            </div>
                            <div class="col-md-6 col-lg-5">
                                <label class="control-label col-md-3 col-lg-3">开单日期：</label>
                                <div class="col-md-3 col-lg-2">
                                    <select id="data_select" class="input-s form-control"></select>
                                </div>
                                <div class="input-daterange input-group" id="datepicker">
                                    <input type="text" name="beginTime" id="beginTime" placeholder="起始日期" class="input-sm form-control" style="width:100px" autocomplete="off">
                                    <span class="input-group-addon">至</span>
                                    <input type="text" name="endTime" id="endTime" placeholder="结束日期" class="input-sm form-control" style="width:100px" autocomplete="off" />
                                </div>
                            </div>

                        </div>
                        <div class="row">
                            <div class="col-md-12 col-lg-6" style="margin-top:15px;">
                                <div class="col-md-3 col-lg-3">
                                    <label class="control-label col-md-4 col-lg-5">状态：</label>
                                    <div class="input-group">
                                        <enums asp-enum="typeof(ExamineStatus)" asp-valuetype="1" asp-name="ExamineStatus" id="ExamineStatus" asp-isdefault="true" class="form-control"></enums>
                                    </div>
                                </div>
                                <div class="col-md-4 col-lg-4">
                                    <label class="control-label col-md-5 col-lg-5">缴款状态：</label>
                                    <div class="input-group">
                                        <enums asp-enum="typeof(RestaurantPayStatus)" asp-valuetype="1" asp-name="RestaurantPayStatus" id="RestaurantPayStatus" asp-isdefault="true" class="form-control"></enums>
                                    </div>
                                </div>
                                <div class="col-md-3 col-lg-4">
                                    <label class="control-label col-md-4 col-lg-5">线路：</label>
                                    <div class="input-group">
                                        @Html.DropDownList("Line", ViewBag.Line as IEnumerable<SelectListItem>, "全部", new { @class = "form-control", id = "Line" })
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12 col-lg-12" style="margin-top:15px;">
                                <div class="col-md-6 col-lg-6">
                                    <label class="control-label col-md-3 col-lg-2">配送日期：</label>
                                    <div class="col-md-3 col-lg-2">
                                        <select id="data_select2" class="input-s form-control"></select>
                                    </div>
                                    <div class="input-daterange input-group" id="datepicker">
                                        <input type="text" name="beginDate" id="beginDate" placeholder="起始日期" class="input-sm form-control" style="width:100px" autocomplete="off">
                                        <span class="input-group-addon">至</span>
                                        <input type="text" name="endDate" id="endDate" placeholder="结束日期" class="input-sm form-control" style="width:100px" autocomplete="off" />
                                    </div>
                                </div>
                                <div class="col-md-6 col-lg-6">
                                    <span class="input-group-btn block">
                                        <button type="submit" class="btn btn-sm btn-primary"> 查询</button>
                                        @if (IsGranted(FwProject.Authorization.PermissionNames.Finance_Operation_ReceiptApproval))
                                        {
                                            <button type="button" class="btn btn-sm btn-info" id="batch">批量审批</button>
                                        }
                                        @if (IsGranted(FwProject.Authorization.PermissionNames.Finance_Operation_ReceiptDelete))
                                        {
                                            <button type="button" class="btn btn-sm btn-danger" id="btnDelete">删除单据</button>
                                        }
                                        @if (IsGranted(FwProject.Authorization.PermissionNames.Finance_Operation_ReceiptPrint))
                                        {
                                            <button type="button" class="btn btn-sm btn-success" id="print">单据打印</button>
                                        }
                                        @if (IsGranted(FwProject.Authorization.PermissionNames.Finance_Operation_DeliveryDetailsPrint))
                                        {
                                            <button type="button" class="btn btn-sm btn-success" id="printDistirbution">打印配送明细</button>
                                        }
                                        @if (IsGranted(FwProject.Authorization.PermissionNames.Finance_Operation_StatementPrint))
                                        {
                                            <button type="button" class="btn btn-sm btn-success" id="printDZ">打印对账单</button>
                                        }

                                    </span>
                                </div>
                            </div>

                        </div>
                    </form>
                </div>
                <div id="data_list">
                    @*@{Html.RenderPartial("IndexPartial", Model);}*@
                </div>
            </div>
        </div>
    </div>
</div>

@section scripts{
    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Theme/js/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Theme/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="~/Theme/js/plugins/suggest/bootstrap-suggest2014.js"></script>
    <script src="~/js/DateComm.js"></script>
    <script src="~/js/PrintUtil.js?v=2.0"></script>
    <script type="text/javascript">
        function Print() {
            printGirdObj({
                containerId: 'table_print',//包含表格容器のID
                title: '收据查询',
                showRowNum: false,  //表格中rownumbers: true时为true
                showOrder: false,//是否显示序号，rownumbers: true时有效，默认false
                printInit: { //打印初始化设置参数
                    portrait: false //true纵向,false横向
                }
            });
        }

        function Export() {
            var RestaurantName = $('#RestaurantName').val();
            var DriverName = $('#DriverName').val();
            var beginTime = $('#beginTime').val();
            var endTime = $('#endTime').val();
            var ExamineStatus = $('#ExamineStatus').val();
            var RestaurantPayStatus = $('#RestaurantPayStatus').val();
            var Line = $('#Line').val();
            window.location.href = "/Settlement/ExportExcel?RestaurantName=" + RestaurantName + "&beginTime=" + beginTime + "&endTime=" + endTime + "&DriverName" + DriverName + "&ExamineStatus" + ExamineStatus + "&RestaurantPayStatus" + RestaurantPayStatus + "&Line" + Line;
        }

        $("#print").on("click", function () {
            var t = $("#t tbody").find('input[type="checkbox"]');
            var ids = [];
            for (var i = 0; i < t.length; i++) {
                if ($(t[i]).prop('checked')) {
                    ids.push($(t[i]).val());
                }
            }
            if (ids.length == 0) {
                layer.msg('请至少选择一条单据！！', {
                    icon: 2,
                    time: 2000
                });
                return false;
            }
            window.open("/Settlement/SettlementPrint?Ids=" + ids.join('|'));

        })

        $("#batch").on("click", function () {
            var t = $("#t tbody").find('input[type="checkbox"]');
            var ids = [];
            for (var i = 0; i < t.length; i++) {
                if ($(t[i]).prop('checked')) {
                    ids.push($(t[i]).val());
                }
            }
            if (ids.length == 0) {
                layer.msg('请至少选择一条单据！！', {
                    icon: 2,
                    time: 2000
                });
                return false;
            } else {
                layer.confirm('您确定要审核？？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.get("/Settlement/BatchReview?Ids=" + ids.join('|'), function (data) {
                        if (data.success) {
                            layer.msg("审批成功！！")
                            top.Refresh();
                        } else {
                            layer.msg("审核失败！！")
                        }
                    });
                });
            }

        })

        $("#btnDelete").on("click", function () {
            var t = $("#t tbody").find('input[type="checkbox"]');
            var ids = [];
            for (var i = 0; i < t.length; i++) {
                if ($(t[i]).prop('checked')) {
                    ids.push($(t[i]).val());
                }
            }
            if (ids.length == 0) {
                layer.msg('请至少选择一条单据！！', {
                    icon: 2,
                    time: 2000
                });
                return false;
            } else {
                layer.confirm('是否确认删除?', { icon: 3, title: '提示' }, function (index) {
                    $("#SettlementForm").submit();
                    layer.close(index);
                });
                
            }
        })


        $("#printDistirbution").on("click", function () {
            var t = $("#t tbody").find('input[type="checkbox"]');
            var ids = [];
            for (var i = 0; i < t.length; i++) {
                if ($(t[i]).prop('checked')) {
                    ids.push($(t[i]).val());
                }
            }
            if (ids.length == 0) {
                layer.msg('请至少选择一条单据！！', {
                    icon: 2,
                    time: 2000
                });
                return false;
            } else {
                window.open("/Print/PrintDistribution?ids=" + ids.join('|'));
            }
        })

        $("#printDZ").on("click", function () {
            var t = $("#t tbody").find('input[type="checkbox"]');
            var ids = [];
            for (var i = 0; i < t.length; i++) {
                if ($(t[i]).prop('checked')) {
                    ids.push($(t[i]).val());
                }
            }
            if (ids.length == 0) {
                layer.msg('请至少选择一条单据！！', {
                    icon: 2,
                    time: 2000
                });
                return false;
            } else {
                window.open("/Print/PrintDz?ids=" + ids.join('|'));
            }
        })

        $(document).ready(function () {


            $("body").on("click", ".table>tbody>tr td.collapsed i", function (e) {
                e.preventDefault();
                if ($(this).hasClass("fa-plus-square-o")) {
                    $(this).removeClass("fa-plus-square-o").addClass("fa-minus-square-o").parent().parent().next(".tb-child").removeClass("hidden");
                    var id = $(this).data("id");
                    var tb = $(this).removeClass("fa-plus-square-o").addClass("fa-minus-square-o").parent().parent().next(".tb-child").find(".tb_tbody");
                    tb.empty();

                    $.getJSON("/Settlement/GetDistributionInfo?id=" + id).done(function (data) {
                        var date;
                        if (data.success) {
                            if (data.result.length > 0) {
                                for (var i = 0; i < data.result.length; i++) {
                                    var tr = $('<tr>');
                                    date = top.dateFtt("yyyy-MM-dd hh:mm:ss", new Date(data.result[i].creationTime))
                                    tr.append('<td>' + data.result[i].creationNumber + '</td>').append('<td>' + date + '</td>').append('<td>' + data.result[i].totalPrice + '</td>');
                                    tb.append(tr);
                                }
                            }

                        }
                    })
                }
                else {
                    $(this).removeClass("fa-minus-square-o").addClass("fa-plus-square-o").parent().parent().next(".tb-child").addClass("hidden");
                }
            });

            //$.getJSON("/Users/GetSuggestData?type=司机类型").done(function (data) {
            //    CommonAjaxCallback(data, function () {
            //        bindSuggest(data.result);
            //    }, null);
            //}).fail(function () {
            //    layer.msg('连接超时，获取司机信息失败！', {
            //        icon: 2,
            //        time: 2000
            //    });
            //});

            $('#modal_ajax').on('show.bs.modal', function (e) {
                $(this).addClass('loading');
                var $button = $(e.relatedTarget);
                var url = $button.data('url');
                if (!!url) {
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                    $(this).load(url, function () {
                        $.validator.unobtrusive.parse(this); //$("#form_model_create").validate();
                        $("input[name='CreationTime']").datepicker({ todayBtn: "linked", keyboardNavigation: !1, forceParse: !1, calendarWeeks: !0, autoclose: !0 });
                        $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
                        $(this).removeClass('loading');
                    });
                }
            });
            //开始时间
            $('#beginTime').datepicker({
                todayBtn: "linked",
                autoclose: true,
                todayHighlight: true

            }).on('changeDate', function (e) {
                var startTime = e.date;
                $('#endTime').datepicker('setStartDate', startTime);
            });
            //结束时间：
            $('#endTime').datepicker({
                todayBtn: "linked",
                autoclose: true,
                todayHighlight: true

            }).on('changeDate', function (e) {
                var endTime = e.date;
                $('#beginTime').datepicker('setEndDate', endTime);
            });


            $('#beginDate').datepicker({
                todayBtn: "linked",
                autoclose: true,
                todayHighlight: true

            }).on('changeDate', function (e) {
                var startTime = e.date;
                $('#endDate').datepicker('setStartDate', startTime);
            });
            //结束时间：
            $('#endDate').datepicker({
                todayBtn: "linked",
                autoclose: true,
                todayHighlight: true

            }).on('changeDate', function (e) {
                var endTime = e.date;
                $('#beginDate').datepicker('setEndDate', endTime);
            });

            $('#form').submit();

        });

        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                window.location.reload();
            }, successInfo);
        }

        function bindSuggest(data) {
            if ($("#dropdown-driverid") != undefined) {
                $role = $("#dropdown-driverid").bsSuggest({
                    effectiveFields: ["name"],
                    effectiveFieldsAlias: { "name": "姓名" },
                    searchFields: ["name"],
                    clearable: true,
                    getDataMethod: "data",
                    //url: "/Users/GetSuggestData?type=司机类型&keyword=",
                    data: { value: data },
                    idField: "id",
                    keyField: "name",
                    callfun: function () {
                        $("#DriverId").val("");
                    }
                }).on('onDataRequestSuccess', function (e, result) {
                    console.log('onDataRequestSuccess: ', result);
                }).on('onSetSelectValue', function (e, keyword, data) {
                    $("#DriverId").val(data.id);
                    console.log('onSetSelectValue: ', keyword, data);
                }).on('onUnsetSelectValue', function () {
                    console.log('onUnsetSelectValue');
                });
            }
        }
        function blurEmpty() {
            var cityObj = $("#dropdown-driverid");
            var DriverId = $("#DriverId");
            if (cityObj.val() == "") {
                DriverId.attr("value", "");
            }
        }

        new DateContUtil({//【下拉日期】
            selectId: "data_select",//下拉框のID
            startDate: 'beginTime',//开始日期(不填默认search_startDateBase)
            endDate: 'endTime',//结束日期(不填默认search_endDateBase)
            defaultValue: '4',//本月
            selectedFun: function () {//选中后触发の方法
                $("#form").submit();
            }
        });

        new DateContUtil({//【下拉日期】
            selectId: "data_select2",//下拉框のID
            startDate: 'beginDate',//开始日期(不填默认search_startDateBase)
            endDate: 'endDate',//结束日期(不填默认search_endDateBase)
            defaultValue: '4',//本月
            selectedFun: function () {//选中后触发の方法
                $("#form").submit();
            }
        });

        function LoadDataSuccessMessage() {
            layer.closeAll();
            $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
            $('#chkDiv').on('ifChecked', function (event) { //ifCreated 事件应该在插件初始化之前绑定
                $("#t tbody").find('.i-checks').iCheck('check');
            });
            $('#chkDiv').on(' ifUnchecked', function (event) { //ifCreated 事件应该在插件初始化之前绑定
                $("#t tbody").find('.i-checks').iCheck('uncheck');
            });
        }


        $("#data_list").on("change", "#pageSize", function () {
            layer.load();
            var size = $("option:selected", this).val();
            var pageurl = $("#pageurl").val();
            $("#data_list").load("/Settlement/Index?size=" + size + "&r=" + Math.random() + pageurl, function () {
                layer.closeAll();
                $("#size").val($("option:selected", this).val());
                LoadDataSuccessMessage();
            });
        });
    </script>
}